﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sinacor.Infra.Service.Data;
using System.Data.Common;
using Sinacor.Infra.Service.Common;

namespace Sinacor.OMM.Configuration.OrderBovespaSystem
{
    public class OrderBovespaSystemConfigurationReader : BaseResourceAccess
    {

        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="companyId"></param>
        public OrderBovespaSystemConfigurationReader(Int32 companyId)
            : base(companyId)
        {

        }

        #endregion

        #region Methods

        /// <summary>
        /// Get Order Bovespa System Information
        /// </summary>
        /// <returns></returns>
        public OMM.Configuration.OrderBovespaSystem.OrderBovespaSystemConfiguration GetOrderBovespaSystemInformation()
        {
            //
            String sqlCommand = String.Empty;
            OMM.Configuration.OrderBovespaSystem.OrderBovespaSystemConfiguration information = null;

            sqlCommand = @"SELECT TRUNC(DT_DATMOV) DT_DATMOV
                                    ,TP_MOVIMENTO
                                    ,DT_VERSAO
                           FROM TORDATMOV";

            using (DbCommand command = this.DataBase.GetSqlStringCommand(sqlCommand))
            {
                information = this.FindOne<OMM.Configuration.OrderBovespaSystem.OrderBovespaSystemConfiguration>(command,
                    reader =>
                    {
                        OMM.Configuration.OrderBovespaSystem.OrderBovespaSystemConfiguration item = new OMM.Configuration.OrderBovespaSystem.OrderBovespaSystemConfiguration();

                        item.SystemDate = reader.GetValue<DateTime>("DT_DATMOV");
                        item.VersionDate = reader.GetValue<DateTime>("DT_VERSAO");
                        item.State = EnumConverter.Parse<OMM.Configuration.OrderBovespaSystem.SystemState>(reader.GetValue<String>("TP_MOVIMENTO"));

                        return item;
                    });
            }

            return information;
        }


        #endregion

    }
}
